package com.spider.moudle.factory;

import com.spider.moudle.util.PropertiesUtil;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;

import java.util.Properties;

/**
 * Created by Linbo Hu on 2017/12/4.
 * kafka生成者工厂
 */
public class KafkaProducerFactory {

    private static Properties producer_properties = new Properties();

    static {
        producer_properties.put("bootstrap.servers", PropertiesUtil.getVal("kafka.server.path"));
        producer_properties.put("producer.type", "sync");
        producer_properties.put("request.required.acks", "1");
        producer_properties.put("serializer.class", "kafka.serializer.DefaultEncoder");
        producer_properties.put("key.serializer", "org.apache.kafka.common.serialization.ByteArraySerializer");
        producer_properties.put("value.serializer", "org.apache.kafka.common.serialization.ByteArraySerializer");
        producer_properties.put("max.request.size", "67108864");
        producer_properties.put("request.timeout.ms", "10000");
        producer_properties.put("batch.size", "32108864");
        producer_properties.put("buffer.memory", "67108864");
    }


    public static KafkaProducer<byte[], byte[]> build() {
        return new KafkaProducer<>(producer_properties);
    }

}
